﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Chinaer.Core.Helper
{
    public class DirectoryHelper
    {
        /// <summary>
        /// 监测目录是否存在
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public static bool CheckDirectoryExists(string directory)
        {
            return Directory.Exists(directory);
        }
        /// <summary>
        /// 创建目录
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public static bool CreateDirectory(string directory)
        {
            try
            {
                Directory.CreateDirectory(directory);
                return CheckDirectoryExists(directory);
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        /// <summary>
        /// 删除目录
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public static bool DeleteDirectory(string directory)
        {
            try
            {
                Directory.Delete(directory, true);
                return !CheckDirectoryExists(directory);
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
